﻿using MediatR;
using Sale.Api.Application.Command.Ladder;
using Sale.Domain;
using Sale.ErrorCode;
using Sale.Infrastructure.Interface;

namespace Sale.Api.Application.Handler.Ladder
{
    public class GetLadderHandler : IRequestHandler<GetLadderCommand, ApiResult<List<LadderModel>>>
    {
        private readonly IBaseRepository<LadderModel> ladderRepo;
        private readonly ILogger<GetLadderHandler> logger;

        public GetLadderHandler(IBaseRepository<LadderModel> ladderRepo,ILogger<GetLadderHandler> logger)
        {
            this.ladderRepo = ladderRepo;
            this.logger = logger;
        }
        public Task<ApiResult<List<LadderModel>>> Handle(GetLadderCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<LadderModel>> result=new ApiResult<List<LadderModel>>();
            var ladder = ladderRepo.GetAll().Where(x => x.IsDel == false);
            result.Code = ApiEnum.OK;
            result.Data=ladder.ToList();
            result.Msg = "阶梯折扣显示成功";
            logger.LogInformation(result.Msg);
            return Task.FromResult(result);
        }
    }
}
